

<template>
  <a-modal v-model="visible" :width="300" centered :footer="null" class="return-modal" :maskClosable="false" :closable="false">
    <div v-if="ment">
      <div style="padding: 40px 50px">会员的好友（尾号：{{ othersPhone }}）正在支付代付订单，请等待。（剩余{{ minute2 }}分{{ second2 }}秒）</div>
      <div class="return" @click="cancel">返回</div>
    </div>
    <div v-if="behalf">
      <div style="padding: 40px">会员有正在进行中的代付订单,继续还货会取消代付订单。请先和会员确认。</div>
      <div class="still">
        <a-button style="margin-right: 10px; cursor: pointer" @click="cancel">返回</a-button>
        <a-button type="primary" @click="affirm">已确认 ,继续还货</a-button>
      </div>
    </div>
  </a-modal>
</template>
    
    <script>
import { validLink, cancelOthersPay } from '@/api/box/order'
export default {
  data() {
    return {
      visible: false,
      ment: false,
      behalf: false,
      othersPayShare: {},
      customerLogisticsId: '',
      timer2: '',
      othersPhone: '',
      minute2: '',
      second2: ''
    }
  },
  methods: {
    show(othersPayShare, customerLogisticsId) {
      this.othersPayShare = othersPayShare

      this.customerLogisticsId = customerLogisticsId

      this.visible = true
      this.postLink(othersPayShare.id)
    },
    postLink(id) {
      let data = {
        requestData: {
          id: id
        }
      }
      validLink(data).then(res => {
        if (res.code == 0) {
          // console.log(res.data.code)
          // console.log(res.data.validFlag)
          if (res.data.code == 3004) {
            this.othersPhone = res.data.othersPhone ? res.data.othersPhone.substr(res.data.othersPhone.length - 4) : ''
            this.countDown(res.data.preOrderTime)
            this.ment = true
            return
          } else if (res.data.code == 3008) {
            console.log(this.behalf, 'this.behalf')
            console.log(this.ment, 'this.ment')
            this.othersPhone = res.data.othersPhone ? res.data.othersPhone.substr(res.data.othersPhone.length - 4) : ''
            this.countDown(res.data.preOrderTime)
            this.ment = true
            return
          } else if (res.data.code == 3009) {
            this.behalf = false
            this.ment = false
            this.affirm()
          } else if (res.data.validFlag) {
            this.behalf = true
          } else {
            this.behalf = false
            this.ment = false
            this.affirm()
          }
        }
      })
    },
    cancel() {
      this.visible = false
      this.behalf = false
    },
    affirm() {
      this.visible = false
      let data = {
        requestData: {
          id: this.othersPayShare.id,
          orderSn: this.othersPayShare.orderSn,
          ownerUnionId: this.othersPayShare.ownerUnionid
        }
      }
      cancelOthersPay(data).then(res => {
        if (res.code == 0) {
          this.visible = false
          this.behalf = false

          let record = {
            customerLogisticsId: this.customerLogisticsId,
            unionId: this.othersPayShare.ownerUnionid,
            id: this.othersPayShare.boxId
          }

          this.$emit('returnModal', record)
        } else {
          // console.log(this.visible)
          // console.log(this.behalf)
          this.visible = false
          this.behalf = false
        }
      })
    },

    countDown(time) {
      let self = this

      let timer2 = setInterval(function () {
        //周期计时器，每隔1秒执行一次方法里的代码
        //得到一个从现在时间开始到活动结束的时间戳
        var downTime = parseInt(new Date(time.replace(/-/g, '/')).getTime() + 4 * 60 * 1000 + 5000 - new Date().getTime())
        // 倒计时结束
        console.log(downTime)
        if (downTime <= 0) {
          console.log(downTime)
          self.visible = false
          self.ment = false
          self.behalf = false
          //结束周期计时器
          clearInterval(timer2)
          return
        }
        //计算距离活动还有多少天、时、分、秒

        var m = parseInt((downTime / 1000 / 60) % 60)
        var s = parseInt((downTime / 1000) % 60)
        //统一格式的显示

        m < 10 ? (m = '0' + m) : m
        s < 10 ? (s = '0' + s) : s
        //同步显示

        self.minute2 = m
        self.second2 = s
      }, 1000)
    }
  }
}
</script>
    
 <style lang="less" scoped>
.return {
  border-top: 1px solid #eee;
  text-align: center;
  padding: 10px;
  color: #1890ff;
  cursor: pointer;
}
/deep/ .ant-modal-body {
  padding: 0px !important;
}
.still {
  display: flex;
  justify-content: end;
  padding: 10px;
  border-top: 1px solid #eee;
  text-align: center;
}
</style>